<template lang="pug">
  div.table-empty
    s-table(
      ref="table"
      reqMethod="get"
      :reqUrl="reqUrl"
      :column="tableObj.column"
      :filterProps="{ fields: searchField }"
      :selection="false"
      @selection-change="rows => selectedRows = rows"
    )
      template(slot="auditAt" slot-scope="text, scope")
        span {{text | dateFilter('YYYY-MM-DD')}}
      template(slot="audited" slot-scope="text, scope")
        el-tag(size="mini" v-if="scope.audited === 1") 已审核
        el-tag(size="mini" v-else type="danger") 未审核
      template(slot="loaned" slot-scope="text, scope")
        el-tag(size="mini" v-if="scope.loaned === true") 已发放
        el-tag(size="mini" v-else type="danger") 未发放
      template(slot="action" slot-scope="text, scope")
        el-popconfirm(
          title="您确认对该备用金申请进行发放？"
          @confirm="() => actionHandle(scope)"
          @onConfirm="() => actionHandle(scope)"
        )
          el-link(slot="reference" v-if="scope.loaned !== true && scope.audited === 1" type="primary") 发放
</template>
<script>
import { column } from './config'
import { mapGetters } from 'vuex'
import { loanImprest } from './api'
export default {
  components: {
  },
  data () {
    return {
      tableObj: {
        column
      },
      tableData: [],
      selectedRows: [],
      classes: [],
      classId: '',
      childName: ''
    }
  },
  computed: {
    ...mapGetters(['curArea']),
    reqUrl () {
      return '/v2/imprest/list'
    },
    searchField () {
      return [
        {
          key: 'createdByName',
          label: '申请人'
        }
      ]
    }
  },
  created () {
  },
  methods: {
    refreshTable (flag = false) {
      this.$refs.table.refresh(flag)
    },
    actionHandle (row, type) {
      loanImprest({ id: row.id, loaned: 1 }).then(res => {
        this.refreshTable()
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.table-operator{
  margin-bottom: 18px
}
::v-deep{
  .tableWrapper{
    padding: 0
  }
}
</style>
